package leetcode;

public class Day24 {
    public int maxTurbulenceSize(int[] arr) {
        int n=arr.length;
        int[] dp=new int[n];
        if(n==1){
            return 1;
        }
        boolean flag=true;
        for(int i=1;i<n;i++){
            if(arr[i]!=arr[i-1]){
                flag=false;
            }
        }
        if(flag==true){
            return 1;
        }
        if(n==2){
            return 2;
        }
        dp[0]=1;
        dp[1]=2;
        int max=Integer.MIN_VALUE;
        for(int i=2;i<n;i++){
            if((arr[i-1]>arr[i-2]&&arr[i-1]>arr[i])||(arr[i-1]<arr[i-2])&&arr[i-1]<arr[i]){
                dp[i]=dp[i-1]+1;
            }else{
                dp[i]=2;
            }
            if(dp[i]>max){
                max=dp[i];
            }
        }
        return max;
    }
    public static void main(String[] args) {
        int[] arr={9,4,2,10,7,8,8,1,9};
    }
}
